package rabbitmq_5;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

//工作模式发生消息
public class Producer_5 {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory c = new ConnectionFactory();
        c.setHost("192.168.64.140");
        c.setPort(5672);
        c.setUsername("admin");
        c.setPassword("admin");

        Connection ch = c.newConnection();
        Channel cha = ch.createChannel();
        //定义陆游模式交换机
        cha.exchangeDeclare("topic_logs", BuiltinExchangeType.TOPIC);

        //定义循环发送消息
        while (true){
            System.out.println("请输入消息:");
            String msg = new Scanner(System.in).nextLine();
            System.out.println("请输入陆游建:");
            String key = new Scanner(System.in).nextLine();
            cha.basicPublish("topic_logs",
                    key,    //队列名
                    null,//MessageProperties.PERSISTENT_TEXT_PLAIN,   //其他属性消息持久化
                    msg.getBytes());//转换字节

            System.out.println("发生成功");
        }

    }
}
